var tableManage = function() {

	var _init = function() {

		var table = $('#table_order');
        var userId = $('#userId').val();
		var tableUnit = table.dataTable({
			"processing": true,
			"serverSide": true,
			"ajax": {
				url:posturl,
				data:{"type":'2',"userId":userId}  //收益
			},
			"autoWidth": false,
			"columns": [
				{
					"width": "12%", //买家
					"data": "userName",
					"render": function(data, type, row, meta) {
						if(data=='--'){
							return "未绑定微信昵称";
						}else if(data){
							return data;
						} else {
							return '未绑定微信昵称';
						}
					}
				},
				{
					"width": "8%",//订单号
					"data": "orderNO"
				},
                {
                    "width": "7%",
                    "data": "create_time",//交易时间,
                    "render": function(data, type, row, meta) {
                        if(data){
                            return moment(data).format('YYYY-MM-DD HH:mm');
                        }else{
                            return "--";
                        }
                    }
                },
				{
					"width": "9%",//订单金额
					"data": "total",
					"render": function(data, type, row, meta) {
						if(data){
							return data/100;
						}else{
							return "0";
						}
					}
				},
				{
					"width": "9%",
					"data": "proportion" ,
					"render": function(data, type, row, meta) {
						if(data && row.total){
							return (data/100 * row.total) / 100
						}else{
							return "0"
						}
					}
				},
				{
					"width": "9%",
					"data": "status" ,
					"render": function(data, type, row, meta) {
						if(data == 0){
							return '未到账,可退换货';
						}else if(data == 2){
							return "已抽取拥金";
						} else {
							return '不可退货';
						}
					}
				},
			],
			"language": {
				url: '/public/static/admin/pages/Chinese.json'
			},
			"pageLength": 10,
			"order": [
				[2, "desc"]
			],
			"columnDefs": [{
				"orderable": false,
				"targets": [2]
			}],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
				"<t>" +
				"<'table_b relative'<'col-md-5'i><'col-md-7'>lp>",
            "fnInitComplete": function() {},
            "fnDrawCallback": function() {}
		});
	};

	return {
		init: function() {
			_init();
		}
	};

}();

$(function() {
    tableManage.init();
});